%{
    #include<string.h>
//    #define YYSTYPE char*
    #include "parse.tab.h"
    void yyerror(char *s);
%}

%option yylineno
%option noyywrap

%x STR

%%

[/][/].*\n      ; // comment
[ \t\r\n]       ; // whitespace
[`].+\n         ;

if              return IF;
else            return ELSE;
always          return ALWAYS;
initial         return INIT;
begin           return BEG;
end             return END;
posedge         return POSEDGE;
negedge         return NEGEDGE;
@               return AT;
module          return MODULE;
input           return INPUT;
output          return OUTPUT;
reg             return REG;
wire            return WIRE;
integer         return INTEGER;
[0-1]+[']b[0-9]+    return BIT_MASK;
[0-7]+[']o[0-9]+    return OCT_MASK;
[0-9]+[']d[0-9]+    return DEC_MASK;
[0-9a-fA-F]+[']h[0-9]+  return HEX_MASK;

[a-zA-Z_][a-zA-Z0-9_]*  { yylval.str = yytext;
                        return ID;}
\#[0-9]+        {
                    char* end;
                    char* temp;
                    yylval.mask.value = strtol(yytext+sizeof(char),&end,16); 
                    yylval.mask.bits  = strtol(end+2*sizeof(char),&temp,10);
                    if (*(end+sizeof(char))!='h')
                    {
                        if (*(end+sizeof(char))=='b')
                        {
                            yylval.mask.value = strtol(yytext+sizeof(char),&end,2); 
                            yylval.mask.bits  = strtol(end+2*sizeof(char),&temp,10);
                        }else if (*(end+sizeof(char))=='o')
                        {
                            yylval.mask.value = strtol(yytext+sizeof(char),&end,8);
                            yylval.mask.bits  = strtol(end+2*sizeof(char),&temp,10);
                        }else if (*(end+sizeof(char))=='d')
                        {
                            yylval.mask.value = strtol(yytext+sizeof(char),&end,10);
                            yylval.mask.bits  = strtol(end+2*sizeof(char),&temp,10);
                        }
                    }
                    return TIME;
                }
[0-9]+          { 
                    yylval.mask.value = atoi(yytext);
                    return NUM;
                }
\<=             return EQUAL;
[:\[\]-{};()=<>+*/!,\~]    { return *yytext; }
                yyerror("Invalid character");

%%
